#ifndef SERVER_H
#define SERVER_H

#ifdef WIN32

#include <winsock2.h>

#elif defined (linux)

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h> /* close */
#include <netdb.h> /* gethostbyname */
#define INVALID_SOCKET -1
#define SOCKET_ERROR -1
#define closesocket(s) close(s)
typedef int SOCKET;
typedef struct sockaddr_in SOCKADDR_IN;
typedef struct sockaddr SOCKADDR;
typedef struct in_addr IN_ADDR;

#else

#error not defined for this platform

#endif

#define CRLF		"\r\n"
#define PORT	 	4242
#define MAX_CLIENTS 	42

#define TAILLE_BUFFER	1024
typedef struct
{
	SOCKET sock;
	char name[TAILLE_BUFFER];
}Client;

void winstart(void);
void winstop(void);
void cerveau(void);
int debutConnexion(void);
void finConnexion(int sock);
int lireTexte(SOCKET sock, char *buffer);
void ecrireTexte(SOCKET sock, const char *buffer);
void diffuserMessage(Client *clients, Client client, int actual, const char *buffer, char from_server);
void supprimerClient(Client *clients, int to_remove, int *actual);
void supprimerClients(Client *clients, int actual);

#endif
